<!DOCTYPE html>
<html lang="zh-CN">

<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width,initial-scale=1.0">
    <script src="./js/earthsdk.js"></script>
    <!-- 自定义Css样式 -->
    <link rel="stylesheet" href="./css/example1.css">
    <title>体裁剪</title>
    <style>
        html,
        body,
        #app {
            width: 100%;
            height: 100%;
            margin: 0px;
            padding: 0px;
        }


        .box {
            display: grid;
            grid-template-columns: 1fr 1fr;
            margin-bottom: 10px;
            grid-row-gap: 5px;
            align-items: center;
        }

        button {
            padding-left: 20px;
            padding-right: 31px;
        }
    </style>
</head>

<body>
    <div id="app"></div>
    <div id="panel">
        <div class="box">
            <label for="edgeWidth">轮廓线宽度</label><input type="number" id="edgeWidth" value="2"
                onchange="setEdgetWidth()">

            <label for="length">长</label><input type="number" id="length" value="19" onchange="updateSize()">
            <label for="width">宽</label><input type="number" id="width" value="19" onchange="updateSize()">
            <label for="height">高</label><input type="number" id="height" value="19" onchange="updateSize()">
        </div>
        <button onclick="resetEdit()">重新选择裁剪位置</button>
        <button onclick="editing()">编辑位置</button>
    </div>
    <script>

        /** -----------------------------------------地球创建----------------------------------------------------**/

        // Vue中引入方式：import { ESObjectsManager } from 'esobjs-xe2-plugin/dist-node/esobjs-xe2-plugin-main';

        const { ESObjectsManager } = XE2['esobjs-xe2-plugin-main']
        const objm = new ESObjectsManager();
        window.g_objm = objm;

        // 创建Cesium视口
        const viewer = objm.createCesiumViewer({
            domid: document.getElementById("app"),
        });
        viewer.ionAccessToken = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJqdGkiOiIyZmQzMDI1OC1kMWYyLTQ1ZjEtYTJmNS0yMjY1ZDcxZjEyOTkiLCJpZCI6NjQ3MTgsImlhdCI6MTYyOTQzNDM5M30.m8vkzG05QiAfe6JQ0XPK8z_6KuUVMf_CoSY-YlMnAIg"
        // 监听视口状态
        viewer.statusChanged.don(status => {
            if (status == 'Created') {
                // 视口创建完成，飞到初始视角位置
                objm.activeViewer.flyIn(
                    [
                        108.960944507017,
                        34.219759660640435,
                        494.9315139069212
                    ], [
                    263.58063972103986,
                    -25.773219891830262,
                    0.00003932886719282565
                ]
                )
            }
        })

        // 通过json创建一个影像图层
        const imageryLayer = objm.createSceneObjectFromJson({
            "id": "9812a65f-0de0-4f7b-b234-809c0c2fb8ef",
            "type": "ESImageryLayer",
            "maximumLevel": 18,
            "url": "https://server.arcgisonline.com/arcgis/rest/services/World_Imagery/MapServer/tile/{z}/{y}/{x}"
        });

        //添加3DTileset
        const eS3DTileset = objm.createSceneObjectFromJson({
            "id": "c2c8311e-6e50-47a2-b764-1c82f2d0e256",
            "type": "ES3DTileset",
            "name": "ES3DTileset",
            "allowPicking": true,
            "url": "https://www.pipeser.com/cesiumlab/G7qC5vBk/tileset.json"
        })


        /**-----------------------------根据类（Class）创建一个ESBoxClipping裁剪对象-------------------------------**/

        // Vue中引入方式：import { ESBoxClipping } from 'esobjs-xe2-plugin/dist-node/esobjs-xe2-plugin-main';
        const { ESBoxClipping } = XE2['esobjs-xe2-plugin-main']
        const cuttingObject = objm.createSceneObject(ESBoxClipping)
        cuttingObject.size = [19, 19, 19]

        //设置裁剪的3dtileset对象的id
        cuttingObject.targetID = eS3DTileset.id
        // 设置裁剪的基准位置
        cuttingObject.position = [108.9594119, 34.2197855, 471.633]

        // 编辑
        function editing() {
            cuttingObject.editing = true
        }

        // 设置长宽高
        function updateSize() {
            let length = parseInt(document.getElementById("length").value);
            let width = parseInt(document.getElementById("width").value);
            let height = parseInt(document.getElementById("height").value);

            cuttingObject.size = [length, width, height]

        }
        // 设置轮廓线宽度
        function setEdgetWidth() {
            cuttingObject.edgeWidth = Number(document.getElementById('edgeWidth').value)

        }

        // 重新绘制
        function resetEdit() {
            cuttingObject.editing = false
            cuttingObject.position = [0, 0, 0]
            cuttingObject.editing = true
        }
    </script>


</body>

</html>